<template>
    <div class="common-box" v-if="boxIsShow">
        <div class="common-content-box">
            <div class="content-table-box">
                <div class="content_table_title_box">
                    <img src="@/assets/icon-data.png" class="content_table_title_icon">
                    <div class="content_table_title">素材模板资源包</div>
                </div>
                <div class="table_search_box">
                    <!-- <el-form :inline="true" :model="searchForm" class="demo-form-inline" style="display: inline-block;">
                        <el-form-item label="租户名称" style="margin-bottom: 0;">
                            <el-input v-model="searchForm.name" placeholder="请输入租户名称" size="small"></el-input>
                        </el-form-item>
                        <el-form-item style="margin-bottom: 0;">
                            <el-button type="primary" @click="onSubmit" size="small">查询</el-button>
                        </el-form-item>
                    </el-form> -->
                    <el-button type="primary" @click="toAdd" style="float: right;margin-right: 2%;">新增分类</el-button>
                </div>
                <div class="table_box">
                    <el-table
                        :data="tableData"
                        style="width: 100%;"
                        height="92%">
                        <el-table-column
                        fixed
                        prop="id"
                        label="资源包编号"
                        width="200">
                        </el-table-column>
                        <el-table-column
                        prop="name"
                        label="资源包名称"
                        width="200">
                        </el-table-column>
                        <el-table-column
                        label="操作"
                        width="250">
                        <template slot-scope="scope">
                            <el-button @click="toEdit(scope.row)" type="text" size="medium">编辑</el-button>
                            <el-button @click="openTips(scope.row.id)" type="text" size="medium " style="color: #FF0101;">删除</el-button>
                            <el-button @click="toSortList(scope.row.id,1)" type="text" size="medium">正面模板</el-button>
                            <el-button @click="toSortList(scope.row.id,2)" type="text" size="medium">反面模板</el-button>
                        </template>
                        </el-table-column>
                    </el-table>
                    <pagination
                    :total="total"
                    :limit="pageSize"
                    :page="pageNumber"
                    :pageSize="pageSize"
                    @pageChange="pageChange"
                    ></pagination>
                </div>
            </div>
        </div>
        <add-templatePackage 
            ref="addTemplatePackage"
            @close="
            getData();
            "
        ></add-templatePackage>
      <tips-box
          ref="tipsBox"
          @confirmTip="confirmTip"
        ></tips-box>
        
        <template-sort
            ref="templateSort"
        ></template-sort>
    </div>
</template>
<script>
import Pagination from "@/components/pagination.vue";
import addTemplatePackage from "@/components/addTemplatePackage.vue";
import tipsBox from "@/components/tipsBox.vue";
import templateSort from "@/components/templateSort.vue";

export default {
  components: {
    Pagination,
    addTemplatePackage,
    tipsBox,
    templateSort
  },
  data() {
    return {
        total: 0,
        pageSize: 30,
        pageNumber: 1,
        tableData: [],
        boxIsShow:false,
        searchForm:{
          name:''
        },
        tableData: []
    };
  },
  created() {
    
  },
  mounted(){
    
  },
  methods: {
    __init() {
      this.getData();
    },
    getData(){
      var url="manager/getTemplatePackageByPage";
      var params={
        pageSize: this.pageSize,
        pageNum: this.pageNumber
      }
      this.$post(url, params).then((res) => {
        console.log(res)
        if (res.code === 0) {
          this.total = res.data.total;
          this.tableData=res.data.list;
        } else {
          this.$message.error(res.msg)
        }
      });
    },
    pageChange(e) {
      console.log(e)
      this.pageNumber = e.page;
      this.getData();
    },
    onSubmit(){
      this.pageNumber=1;
      this.getData();
    },
    toAdd(){
      if (this.$refs.addTemplatePackage) {
        // 显示当前详情
        this.$refs.addTemplatePackage.tkIsShow = true;
        this.$refs.addTemplatePackage.title = "新增资源包";
        this.$refs.addTemplatePackage.__init("add");
      }
    },
    toEdit(item){
      if (this.$refs.addTemplatePackage) {
        // 显示当前详情
        this.$refs.addTemplatePackage.tkIsShow = true;
        this.$refs.addTemplatePackage.title = "编辑资源包名称";
        this.$refs.addTemplatePackage.__init("edit",item);
      }
    },
    openTips(id){
        this.delId=id;
        const tipContent="确定要删除此资源包吗？"
        if (this.$refs.tipsBox) {
            // 显示当前详情
            this.$refs.tipsBox.tkIsShow = true;
            this.$refs.tipsBox.title = "温馨提示";
            this.$refs.tipsBox.tipContent=tipContent;
        }
    },
    closeTips(){
        if (this.$refs.tipsBox) {
            // 显示当前详情
            this.$refs.tipsBox.tkIsShow = false;
        }
    },
    confirmTip(){
        this.delTemplatePackage();
    },
    delTemplatePackage(){
        var url="manager/delTemplatePackage";
        var params={
            id: this.delId
        }
        this.$post(url, params).then((res) => {
            console.log(res)
            if (res.code === 0) {
                this.$message.success(res.msg)
                this.getData();
                this.closeTips();
            } else {
                this.$message.error(res.msg)
            }
        });
    },
    toSortList(id,type){
        if (this.$refs.templateSort) {
            this.$refs.templateSort.tkIsShow=true;
            this.$refs.templateSort.title="模板图片分类";
            this.$refs.templateSort.__init(id,type);
        }
    }
  }
}
</script>
<style scoped lang="scss">
  .common-box{
    background-color: #f9f9fb;
    height: 100%;
  }
  .common-content-box{
    height: 95%;
    margin-top: 2%;
    width: 96%;
    display: inline-block;
  }
  .content-table-box{
    background-color: #fff;
    width: 100%;
    height: 100%;
    border-radius: 5px;
    box-shadow: 0 0 5px 1px rgba(83, 83, 83, 0.1);
  }
  .content_table_title_box{
    position: relative;
    height: 30px;
    margin-top: 10px;
    width: 100%;
    display: inline-block;
  }
  .content_table_title_icon{
    position: absolute;
    left: 15px;
    height: 18px;
    top: 6px;
  }
  .content_table_title{
    position: absolute;
    line-height: 34px;
    height: 100%;
    font-size: 15px;
    color: #42484e;
    left: 40px;
  }
  .table_search_box{
    text-align: left;
    margin-top: 10px;
    margin-left: 2%;
  }
  .table_box{
    height: calc(100% - 100px);
    margin-top: 10px;
    width: 96%;
    margin-left: 2%;
  }
  ::v-deep .el-form--inline .el-form-item__content{
    width: 140px;
  }
  ::v-deep .el-select>.el-input{
    width: 120px;
  }
</style>